app = new Vue({
  el: '#app',
  data: {
    books: [
      {
        id: 1,
        name: '《算法导论》',
        date: ' 2006-9 ',
        price: 85.00,
        count: 1
      },
      {
        id: 2,
        name: '《UNIX编程艺 术》',
        date: ' 2006-2',
        price: 59.00,
        count: 1
      },
      {
        id: 3,
        name: '《编程珠玑》',
        date: ' 2008 -10',
        price: 39.00,
        count: 1
      }
    ],
  },
  methods: {
    decrement(item) { 
      this.books[item].count = this.books[item].count - 1


    },
    increment(item) { 
      //this.count = this.count + 1
      this.books[item].count = this.books[item].count + 1


    },
    removeHandler(index) { 
      this.books.splice(index,1)

    },
  },
  computed: {
    totalprice() { 
      let totalprice = 0
      for (let n = 0; n < this.books.length; n++) { 
        totalprice = totalprice + this.books[n].price * this.books[n].count
      }
      return totalprice
    },

  },
    //过滤器
  filters: {
    showprice(price) { 
      return "$" + price.toFixed(2)
    }

  }
})